// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility in the flutter_test package. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.

import 'dart:typed_data';

import 'package:flutter_test/flutter_test.dart';

void main() {
  // 十六进制字符串 转换为 Uint8List
  Uint8List hexStringToUint8List(String hexString) {
    // 移除可能存在的空格和前缀（如 "0x"）
    hexString = hexString.replaceAll(" ", "").replaceAll("0x", "");

    // 确保字符串长度为偶数
    if (hexString.length % 2 != 0) {
      throw const FormatException("Invalid hex string length");
    }

    // 创建一个 Uint8List 来存储结果
    Uint8List result = Uint8List(hexString.length ~/ 2);

    // 遍历字符串，每两个字符转换为一个字节
    for (int i = 0; i < hexString.length; i += 2) {
      String hexByte = hexString.substring(i, i + 2);
      int byte = int.parse(hexByte, radix: 16);
      result[i ~/ 2] = byte;
    }

    return result;
  }

  test('Test myFunction', () {
    // debugPrint(
    //     "cmd 1= ${Utils.encodeCmd(0xeffff, isRsp: false, isWrite: false)}");
    // debugPrint("cmd 2= ${Utils.decodeCmd(Uint8List.fromList([46, 255]))}");

    // 从Uint8List中解析 LorinMessage
    // LorinMessage message2 = LorinMessage.fromList(Uint8List.fromList([170]));

    // debugPrint("message2 = ${message2.toBytes()}");
  });
}
